package com.example.recyclerviewdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;
    List<DemoBean> list;

    private void init(){
        recyclerView = findViewById(R.id.recyclerView);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);

        list = getData();
        myAdapter = new MyAdapter(this);
        recyclerView.setAdapter(myAdapter);
        myAdapter.setList(list);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    public List<DemoBean> getData(){
        List<DemoBean> list = new ArrayList<DemoBean>();

        DemoBean demoBean;
        demoBean = new DemoBean();
        demoBean.setId(1);
        demoBean.setTitle("729李子璇");
        demoBean.setImgid(R.drawable.ic_launcher_background);
        demoBean.setDescription("阿巴阿巴");
        demoBean.setTime("2000-04-01");
        list.add(demoBean);
        demoBean = new DemoBean();
        demoBean.setId(2);
        demoBean.setTitle("233李子璇");
        demoBean.setImgid(R.drawable.ic_launcher_background);
        demoBean.setDescription("阿巴阿巴");
        demoBean.setTime("2000-04-01");
        list.add(demoBean);
        return list;
    }
}
